package io.lckgroup.modules.lck.controller.wxmp;

import io.lckgroup.common.utils.R;
import io.lckgroup.modules.lck.annotation.WxLogin;
import io.lckgroup.modules.lck.annotation.WxLoginUser;
import io.lckgroup.modules.lck.entity.CommonCommentEntity;
import io.lckgroup.modules.lck.entity.CustomerInfoEntity;
import io.lckgroup.modules.lck.service.CommonCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huangrui
 */
@RestController
@RequestMapping("/mp/comment")
public class WeiXinCommentController {
    @Autowired
    private CommonCommentService commonCommentService;

    /**
     * 功能描述: <br>
     * 〈〉插入评论，修改订单状态为已评价（ispay = 4）
     *
     * @Param: [commonCommentEntity]
     * @Return: io.lckgroup.common.utils.R
     * @Author: 13980
     * @Date: 2020/4/2 11:04
     */
    @PostMapping("/createComment")
    @WxLogin
    public R createComment(@RequestBody CommonCommentEntity commonCommentEntity, @WxLoginUser CustomerInfoEntity customerInfoEntity) {
//        判断传回信息是否有误 商家ID  订单ID 评分字段
        if (commonCommentEntity.getMerchantId() != null && (commonCommentEntity.getScore() != null) && commonCommentEntity.getOrderMainId() != null) {
            System.out.println(commonCommentEntity);
            commonCommentEntity.setCustomerInfoId(customerInfoEntity.getId());
            int comment = commonCommentService.createComment(commonCommentEntity);
            if (comment > 0) {
                return R.ok();
            } else {
                return R.error("评论失败");
            }

        } else {
            return R.error("评论失败");
        }
    }
}
